home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0068_Erase File ABSOLUTE.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  2KB  |  58 lines

  1. {
  2. Erik Appeldoorn
  3.  
  4. I've made a programm which erases a file absolutely and completely. Even when
  5. it is undeleted it containes nothing.. So far so good.. But when I make a
  6. sector-dump of the disk, it appears that there is still some text on the disk.
  7. I don't get it. Nowhere in my programm I allocated text to memory, but the same
  8. three sentences apear four times in the sector-dump. In the original file the
  9. sentences begin at sentence number 1103. In the sector-dump the four blocks
  10. appear at numbers 72 & 130 & 188 & 248. The totall dump is 251 sentences.
  11. The floppy was newly formatted. What could be happening? Here's part of the
  12. code.
  13. }
  14.  
  15. var ZapFile:File;
  16.     ZapFileName:String;
  17.     ZapFilePos:Longint;
  18.     Buffer:array [1..406] of byte;
  19.     NumWritten, BufferSize, NumRead: word;
  20.  
  21. Procedure deleting(ZapFileName:string);
  22. begin
  23.     Buffersize:=SizeOf(Buffer);
  24.     Assign(ZapFile,ZapFileName);
  25.     {$I-}
  26.     Reset(ZapFile,1);
  27.     {$I+}
  28.     repeat
  29.         ZapFilePos:=FilePos(ZapFile);
  30.         BlockRead(ZapFile,Buffer,BufferSize,NumRead);
  31.         FillChar(Buffer,BufferSize,#255);
  32.         Seek(ZapFile,ZapFilePos);
  33.         BlockWrite(ZapFile,Buffer,NumRead,NumWritten);
  34.     until (NumRead=0) or (NumWritten<>NumRead);
  35.     close(ZapFile);
  36.     Erase(ZapFile);
  37. end;
  38.  
  39.  
  40. {
  41. Jan Doggen
  42.  
  43. I only had time to take a quick look; here are my suggestions:
  44. - forget the reads
  45. - make a CONST buffer, fill it with garbage or zeroes
  46.   (*in* the proc, so that it takes only stack space)
  47. - FS := FileSize(ZapFile)
  48.   NrBlocks := FS DIV BufferSize
  49.   LastBlockSize := FS MOD BufferSize
  50.   For i:=1 to nrblocks blockwrite
  51.   If lastblocksize<>0 write that amount (never mind that the buffer is
  52.   larger)
  53.   close the file
  54. - forget the $I. You don't query IOResult after $I, so all subsequent
  55.   I/O (on *all* files) goes wrong until you do. RTM.
  56. - Instaed of this, use a FileExist function before you call your
  57.   proc.
  58. }